﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Tasker.Composition;

namespace Tasker.WebUI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("DeleteTask", "Task/Delete", new { controller = "Task", action = "Delete" });
            routes.MapRoute("CompleteTask", "Task/Complete", new { controller = "Task", action = "Complete" });
            routes.MapRoute("StopTask", "Task/Stop", new { controller = "Task", action = "Stop" });
            routes.MapRoute("InProccessTask", "Task/InProccess", new { controller = "Task", action = "InProccess" });
            routes.MapRoute("CreateTask", "Task/Create", new { controller = "Task", action = "Create" });
            routes.MapRoute("CreateEmployeeTask", "Task/CreateTaskEmployee", new { controller = "Task", action = "CreateTaskEmployee" });
            routes.MapRoute("CreateSubTask", "Task/CreateSubTask", new { controller = "Task", action = "CreateSubTask" });
            
            routes.MapRoute("EditTask", "Task/{id}/Edit", new { controller = "Task", action = "Edit" });
            routes.MapRoute("ShowTask", "Task/{id}", new { controller = "Task", action = "Index"});
           
            routes.MapRoute("ShowStaffProfile", "Staff/{id}", new { controller = "Staff", action = "ShowProfile" });
            routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

        
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            Bootstrapper.Initialize();
        }

        protected void Application_EndRequest()
        {
            Resolver.DisposeCurrentContext();
        }
    }
}